package org.tailor
class LoginAdminController {
    
  def scaffold = LoginAdmin
  
  def login = {}
  
  def authenticate = {
    def loginAdmin = LoginAdmin.findByLoginAndPassword(params.login, params.password)
    if(loginAdmin){
      session.loginAdmin = LoginAdmin
      flash.message = "Hello ${loginAdmin.name}!"
      redirect(controller:"dashboard", action:"dashboard")      
    }else{
      flash.message = "Sorry, ${params.login}. Please try again."
      redirect(action:"login")
    }
  }
  
  def logout = {
    flash.message = "Goodbye ${session.loginAdmin.name}"
    session.loginAdmin = null
    redirect(controller:"dashboard", action:"dashboard")      
  }  
}